home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / sunprom / RCS / fsDisk.c,v < prev    next >
Encoding:
Text File  |  1990-11-27  |  34.3 KB  |  1,312 lines

  1. head     1.12;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.12
  10. date     90.11.27.11.17.33;  author jhh;  state Exp;
  11. branches ;
  12. next     1.11;
  13.  
  14. 1.11
  15. date     90.11.27.10.45.22;  author rab;  state Exp;
  16. branches ;
  17. next     1.10;
  18.  
  19. 1.10
  20. date     90.09.17.11.04.41;  author jhh;  state Exp;
  21. branches ;
  22. next     1.9;
  23.  
  24. 1.9
  25. date     90.07.17.15.42.26;  author mendel;  state Exp;
  26. branches ;
  27. next     1.8;
  28.  
  29. 1.8
  30. date     89.01.06.08.14.38;  author brent;  state Exp;
  31. branches ;
  32. next     1.7;
  33.  
  34. 1.7
  35. date     87.05.27.14.34.45;  author brent;  state Exp;
  36. branches ;
  37. next     1.6;
  38.  
  39. 1.6
  40. date     87.05.19.12.14.44;  author brent;  state Exp;
  41. branches ;
  42. next     1.5;
  43.  
  44. 1.5
  45. date     87.05.11.11.18.18;  author brent;  state Exp;
  46. branches ;
  47. next     1.4;
  48.  
  49. 1.4
  50. date     87.05.08.17.45.18;  author brent;  state Exp;
  51. branches ;
  52. next     1.3;
  53.  
  54. 1.3
  55. date     86.07.24.11.35.31;  author brent;  state Exp;
  56. branches ;
  57. next     1.2;
  58.  
  59. 1.2
  60. date     86.07.21.09.36.00;  author brent;  state Exp;
  61. branches ;
  62. next     1.1;
  63.  
  64. 1.1
  65. date     86.07.18.09.32.40;  author brent;  state Exp;
  66. branches ;
  67. next     ;
  68.  
  69.  
  70. desc
  71. @Fs_AttachDisk et. al.
  72. @
  73.  
  74.  
  75. 1.12
  76. log
  77. @got it to compile, moved location for sun3 kernel
  78. @
  79. text
  80. @/* 
  81.  * fsDisk.c --
  82.  *
  83.  *    Routines related to managing local disks.  Each partition of a local
  84.  *    disk (partitions are defined by a table on the disk header) is
  85.  *    called a ``domain''.  FsAttachDisk attaches a domain into the file
  86.  *    system, and FsDeattachDisk removes it.  A domain is given
  87.  *    a number the first time it is ever attached.  This is recorded on
  88.  *    the disk so it doesn't change between boots.  The domain number is
  89.  *    used to identify disks, and a domain number plus a file number is
  90.  *    used to identify files.  Fsdm_DomainFetch is used to get the state
  91.  *    associated with a disk, and Fsdm_DomainRelease releases the reference
  92.  *    on the state.  FsDetachDisk checks the references on domains in
  93.  *    the normal (non-forced) case so that active disks aren't detached.
  94.  *
  95.  * Copyright 1987 Regents of the University of California
  96.  * All rights reserved.
  97.  * Permission to use, copy, modify, and distribute this
  98.  * software and its documentation for any purpose and without
  99.  * fee is hereby granted, provided that the above copyright
  100.  * notice appear in all copies.  The University of California
  101.  * makes no representations about the suitability of this
  102.  * software for any purpose.  It is provided "as is" without
  103.  * express or implied warranty.
  104.  */
  105.  
  106. #ifdef notdef
  107. static char rcsid[] = "$Header: /sprite/src/boot/sunprom/RCS/fsDisk.c,v 1.11 90/11/27 10:45:22 rab Exp Locker: jhh $ SPRITE (Berkeley)";
  108. #endif not lint
  109.  
  110.  
  111. #include "sprite.h"
  112.  
  113. #include "fsBoot.h"
  114. #include "devDiskLabel.h"
  115. #include "dev.h"
  116. #include "devFsOpTable.h"
  117. #include "machMon.h"
  118. #include "ofs.h"
  119. /*
  120.  * fsDevice is copied into all Fsio_FileIOHandles.  It is used by the drivers
  121.  * to get to the partition and geometry information for the disk.
  122.  */
  123. Fs_Device fsDevice;
  124.  
  125. /*
  126.  * fsDomainPtr and fsRootHandlePtr are used by Fs_Open.
  127.  */
  128. static Fsdm_Domain fsDomain;
  129. Fsdm_Domain *fsDomainPtr = &fsDomain;
  130. static Fsio_FileIOHandle fsRootHandle;
  131. Fsio_FileIOHandle *fsRootHandlePtr = &fsRootHandle;
  132.  
  133. /*
  134.  * Forward declarations.
  135.  */
  136. static int    InstallLocalDomain();
  137. void        AddDomainFlags();
  138. static Boolean    IsSunLabel();
  139. static Boolean    IsSpriteLabel();
  140.  
  141. /*
  142.  *----------------------------------------------------------------------
  143.  *
  144.  * FsAttachDisk --
  145.  *
  146.  *    Make a particular local disk partition correspond to a prefix.
  147.  *    This makes sure the disk is up, reads the domain header,
  148.  *    and calls the initialization routine for the block I/O module
  149.  *    of the disk's driver.  By the time this is called the device
  150.  *    initialization routines have already been called from Dev_Config
  151.  *    so the device driver knows how the disk is partitioned into
  152.  *    domains.  This routine sees if the domain is formatted correctly,
  153.  *    and if so attaches it to the set of domains.
  154.  *
  155.  * Results:
  156.  *    SUCCESS if the disk was readable and had a good domain header.
  157.  *
  158.  * Side effects:
  159.  *    Sets up the Fsdm_DomainInfo for the domain.
  160.  *
  161.  *----------------------------------------------------------------------
  162.  */
  163. ReturnStatus
  164. FsAttachDisk(fsDevicePtr)
  165.     Fs_Device *fsDevicePtr;        /* Global FS device descriptor */
  166. {
  167.     ReturnStatus status;        /* Error code */
  168.     register Address buffer;        /* Read buffer */
  169.     int headerSector;            /* Starting sector of domain header */
  170.     int numHeaderSectors;        /* Number of sectors in domain header */
  171.     int summarySector;            /* Sector of summary information. */
  172.     Ofs_SummaryInfo *summaryInfoPtr;    /* Pointer to summary info. */
  173.     int amountRead;            /* Returned from read call */
  174.     int devType;            /* Device type index */
  175.     Fs_IOParam    io;            /* I/O Parameter block */
  176.     Fs_IOReply    reply;            /* Results of I/O */
  177.     int flags;
  178.  
  179.     /*
  180.      * Open the raw disk device so we can grub around in the header info.
  181.      */
  182.     devType = DEV_TYPE_INDEX(fsDevicePtr->type);
  183.     status = (*devFsOpTable[devType].open)(&fsDevice, FS_READ, 0, &flags);
  184.     if (status != SUCCESS) {
  185.     return(status);
  186.     }
  187.     buffer = (Address)malloc(DEV_BYTES_PER_SECTOR);
  188.  
  189.     /*
  190.      * Read the zero'th sector of the partition.  It has a copy of the
  191.      * zero'th sector of the whole disk which describes how the rest of the
  192.      * domain's zero'th cylinder is layed out.
  193.      */
  194.     io.offset = 0;
  195.     io.length = DEV_BYTES_PER_SECTOR;
  196.     io.buffer = buffer;
  197.     status = (*devFsOpTable[devType].read)(&fsDevice, &io, &reply);
  198.     if (status != SUCCESS) {
  199.     return(status);
  200.     }
  201.     /*
  202.      * Check for different disk formats, and figure out how the rest
  203.      * of the zero'th cylinder is layed out.
  204.      */
  205.     if (((Sun_DiskLabel *)buffer)->magic == SUN_DISK_MAGIC) {
  206.     Ofs_DomainHeader    *domainHeaderPtr = (Ofs_DomainHeader *) buffer;
  207.     int            i;
  208.     /*
  209.      * For Sun formatted disks we put the domain header well past
  210.      * the disk label and the boot program.
  211.      */
  212.     numHeaderSectors = OFS_NUM_DOMAIN_SECTORS;
  213.     for (i = 2; i < FSDM_MAX_BOOT_SECTORS + 3; i+= FSDM_BOOT_SECTOR_INC) {
  214.         io.offset = i * DEV_BYTES_PER_SECTOR;
  215.         io.length = DEV_BYTES_PER_SECTOR * OFS_NUM_DOMAIN_SECTORS;
  216.         io.buffer = buffer;
  217.         status = (*devFsOpTable[devType].read)(&fsDevice, &io, &reply);
  218.         if (status != SUCCESS) {
  219.         return(status);
  220.         }
  221.         if (domainHeaderPtr->magic == OFS_DOMAIN_MAGIC) {
  222.         headerSector = i;
  223.         summarySector = i - 1;
  224.             break;
  225.         }
  226.     }
  227.     if (i >= FSDM_MAX_BOOT_SECTORS + 3) {
  228.         printf("Fsdm_AttachDisk: Can't find domain header.\n");
  229.         return(FAILURE);
  230.     }
  231.     } else {
  232.     printf("Disk label has bad magic number 0x%x\n", 
  233.         ((Sun_DiskLabel *)buffer)->magic);
  234.     return FAILURE;
  235.     }
  236.     ((Ofs_DomainHeader *) fsDomainPtr->clientData) = 
  237.     (Ofs_DomainHeader *) buffer;
  238.  
  239.      /*
  240.      * Set up the ClientData part of *devicePtr to reference the
  241.      * Ofs_Geometry part of the domain header.  This is used by the
  242.      * block I/O routines.
  243.      */
  244.     fsDevicePtr->data = (ClientData)
  245.     &((Ofs_DomainHeader *) fsDomainPtr->clientData)->geometry;
  246.  
  247.     /*
  248.      * Set up a file handle for the root directory.  What is important
  249.      * is the device info (for Block IO) and the file descriptor itself.
  250.      */
  251.     FsInitFileHandle(fsDomainPtr, FSDM_ROOT_FILE_NUMBER, fsRootHandlePtr);
  252.     return(SUCCESS);
  253. }
  254.  
  255. /*
  256.  *----------------------------------------------------------------------
  257.  * The following routines are used by device drivers to map from block
  258.  * and sector numbers to disk addresses.  There are two sets, one for
  259.  * drivers that use logical sector numbers (i.e. SCSI) and the other
  260.  * for <cyl,head,sector> format disk addresses.
  261.  *----------------------------------------------------------------------
  262.  */
  263.  
  264. /*
  265.  *----------------------------------------------------------------------
  266.  *
  267.  * Fs_BlocksToSectors --
  268.  *
  269.  *    Convert from block indexes (actually, fragment indexes) to
  270.  *    sectors using the geometry information on the disk.  This
  271.  *    is a utility for block device drivers.
  272.  *
  273.  * Results:
  274.  *    The sector number that corresponds to the fragment index.
  275.  *    The caller has to make sure that its I/O doesn't cross a
  276.  *    filesystem block boundary.
  277.  *
  278.  * Side effects:
  279.  *    None.
  280.  *
  281.  *----------------------------------------------------------------------
  282.  */
  283. #define SECTORS_PER_FRAG    (FS_FRAGMENT_SIZE / DEV_BYTES_PER_SECTOR)
  284. #if defined(SCSI_DISK_BOOT) || defined(SUN_PROM_BOOT)
  285. int
  286. Fs_BlocksToSectors(fragNumber, data)
  287.     int fragNumber;    /* Fragment index to map into block index */
  288.     ClientData data;    /* ClientData from the device info */
  289. {
  290.     register Ofs_Geometry *geoPtr;
  291.     register int sectorNumber;    /* The sector corresponding to the fragment */
  292.     register int cylinder;    /* The cylinder number of the fragment */
  293.     register int rotationalSet;    /* The rotational set with cylinder of frag */
  294.     register int blockNumber;    /* The block number within rotational set */
  295.  
  296.     geoPtr         = (Ofs_Geometry *)data;
  297.     blockNumber        = fragNumber / FS_FRAGMENTS_PER_BLOCK;
  298.     cylinder        = blockNumber / geoPtr->blocksPerCylinder;
  299.     if (geoPtr->rotSetsPerCyl > 0) {
  300.     /*
  301.      * Do fancy rotational set mapping.
  302.      */
  303.     blockNumber        -= cylinder * geoPtr->blocksPerCylinder;
  304.     rotationalSet    = blockNumber / geoPtr->blocksPerRotSet;
  305.     blockNumber        -= rotationalSet * geoPtr->blocksPerRotSet;
  306.  
  307.     sectorNumber = geoPtr->sectorsPerTrack * geoPtr->numHeads * cylinder +
  308.               geoPtr->sectorsPerTrack * geoPtr->tracksPerRotSet *
  309.               rotationalSet +
  310.               geoPtr->blockOffset[blockNumber];
  311.     sectorNumber += (fragNumber % FS_FRAGMENTS_PER_BLOCK) * SECTORS_PER_FRAG;
  312.     } else {
  313.     /*
  314.      * Do straight-forward mapping.
  315.      */
  316.     sectorNumber = geoPtr->sectorsPerTrack * geoPtr->numHeads * cylinder +
  317.             fragNumber * SECTORS_PER_FRAG - cylinder * 
  318.             geoPtr->blocksPerCylinder * FS_FRAGMENTS_PER_BLOCK *
  319.             SECTORS_PER_FRAG;
  320.     }
  321.  
  322.     return(sectorNumber);
  323. }
  324. #endif
  325.  
  326. /*
  327.  *----------------------------------------------------------------------
  328.  *
  329.  * Fs_BlocksToDiskAddr --
  330.  *
  331.  *    Convert from block indexes (actually, fragment indexes) to
  332.  *    disk address (head, cylinder, sector) using the geometry information
  333.  *     on the disk.  This is a utility for block device drivers.
  334.  *
  335.  * Results:
  336.  *    The disk address that corresponds to the disk address.
  337.  *    The caller has to make sure that its I/O doesn't cross a
  338.  *    filesystem block boundary.
  339.  *
  340.  * Side effects:
  341.  *    None.
  342.  *
  343.  *----------------------------------------------------------------------
  344.  */
  345. #ifdef XYLOGICS_BOOT
  346. void
  347. Fs_BlocksToDiskAddr(fragNumber, data, diskAddrPtr)
  348.     int fragNumber;    /* Fragment index to map into block index */
  349.     ClientData data;    /* ClientData from the device info */
  350.     Dev_DiskAddr *diskAddrPtr;
  351. {
  352.     register Ofs_Geometry *geoPtr;
  353.     register int sectorNumber;    /* The sector corresponding to the fragment */
  354.     register int cylinder;    /* The cylinder number of the fragment */
  355.     register int rotationalSet;    /* The rotational set with cylinder of frag */
  356.     register int blockNumber;    /* The block number within rotational set */
  357.  
  358.     geoPtr         = (Ofs_Geometry *)data;
  359.     /*
  360.      * Map to block number because the rotational sets are laid out
  361.      * relative to blocks.  After that the cylinder is easy because we know
  362.      * blocksPerCylinder.  To get the head and sector we first get the
  363.      * rotational set (described in fsDisk.h) of the block and the
  364.      * block's sector offset (relative to the rotational set!).  This complex
  365.      * algorithm crops up because there isn't necessarily an even number
  366.      * of blocks per track.  The 'blockOffset' array in the geometry gives
  367.      * a sector index of each successive block in a rotational set. Finally,
  368.      * we can use the sectorsPerTrack to get the head and sector.
  369.      */
  370.     blockNumber        = fragNumber / FS_FRAGMENTS_PER_BLOCK;
  371.     cylinder        = blockNumber / geoPtr->blocksPerCylinder;
  372.     blockNumber        -= cylinder * geoPtr->blocksPerCylinder;
  373.     diskAddrPtr->cylinder = cylinder;
  374.  
  375.     rotationalSet    = blockNumber / geoPtr->blocksPerRotSet;
  376.     blockNumber        -= rotationalSet * geoPtr->blocksPerRotSet;
  377. /*
  378.  * The follow statment had to be broken into two because the compiler used
  379.  * register d2 to do the modulo operation, but wasn't saving its value.
  380.  */
  381.     sectorNumber    = geoPtr->sectorsPerTrack * geoPtr->tracksPerRotSet *
  382.               rotationalSet + geoPtr->blockOffset[blockNumber];
  383.     sectorNumber    +=
  384.             (fragNumber % FS_FRAGMENTS_PER_BLOCK) * SECTORS_PER_FRAG;
  385.  
  386.     diskAddrPtr->head    = sectorNumber / geoPtr->sectorsPerTrack;
  387.     diskAddrPtr->sector = sectorNumber -
  388.               diskAddrPtr->head * geoPtr->sectorsPerTrack;
  389. }
  390. #endif
  391.  
  392. /*
  393.  *----------------------------------------------------------------------
  394.  *
  395.  * Fs_SectorsToRawDiskAddr --
  396.  *
  397.  *      Convert from a sector offset to a raw disk address (cyl, head,
  398.  *      sector) using the geometry information on the disk.  This is a
  399.  *      utility for raw device drivers and does not pay attention to the
  400.  *      rotational position of filesystem disk blocks.
  401.  *
  402.  *    This should be moved to Dev
  403.  *
  404.  * Results:
  405.  *    The disk address that corresponds exactly to the byte offset.
  406.  *
  407.  * Side effects:
  408.  *    None.
  409.  *
  410.  *----------------------------------------------------------------------
  411.  */
  412. #ifdef XYLOGICS_BOOT
  413. int
  414. Fs_SectorsToRawDiskAddr(sector, numSectors, numHeads, diskAddrPtr)
  415.     int sector;        /* Sector number (counting from zero 'til the total
  416.              * number of sectors in the disk) */
  417.     int numSectors;    /* Number of sectors per track */
  418.     int numHeads;    /* Number of heads on the disk */
  419.     Dev_DiskAddr *diskAddrPtr;
  420. {
  421.     register int sectorsPerCyl;    /* The rotational set with cylinder of frag */
  422.  
  423.     sectorsPerCyl        = numSectors * numHeads;
  424.     diskAddrPtr->cylinder    = sector / sectorsPerCyl;
  425.     sector            -= diskAddrPtr->cylinder * sectorsPerCyl;
  426.     diskAddrPtr->head        = sector / numSectors;
  427.     diskAddrPtr->sector        = sector - numSectors * diskAddrPtr->head;
  428. }
  429. #endif
  430.  
  431.  
  432. /*
  433.  *----------------------------------------------------------------------
  434.  *
  435.  * FsDeviceBlockIO --
  436.  *
  437.  *    Map a file system block address to a block device block address 
  438.  *    perform the requested operation.
  439.  *
  440.  * NOTE: This routine is temporary and should be replaced when the file system
  441.  *     is converted to use the async block io interface.
  442.  *
  443.  * Results:
  444.  *    The return status of the operation.
  445.  *
  446.  * Side effects:
  447.  *    Blocks may be written or read.
  448.  *
  449.  *----------------------------------------------------------------------
  450.  */
  451.  
  452. ReturnStatus
  453. FsDeviceBlockIO(readWriteFlag, devicePtr, fragNumber, numFrags, buffer)
  454.     int readWriteFlag;        /* FS_READ or FS_WRITE */
  455.     Fs_Device *devicePtr;    /* Specifies device type to do I/O with */
  456.     int fragNumber;        /* CAREFUL, fragment index, not block index.
  457.                  * This is relative to start of device. */
  458.     int numFrags;        /* CAREFUL, number of fragments, not blocks */
  459.     Address buffer;        /* I/O buffer */
  460. {
  461.     ReturnStatus status;    /* General return code */
  462.     int firstSector;        /* Starting sector of transfer */
  463.     DevBlockDeviceRequest    request;
  464.     int                transferCount;
  465.     int                devType;
  466.     Fs_IOParam            io;        
  467.     Fs_IOReply            reply;    
  468.  
  469.     devType = DEV_TYPE_INDEX(devicePtr->type);
  470.     if ((fragNumber % FS_FRAGMENTS_PER_BLOCK) != 0) {
  471.     /*
  472.      * The I/O doesn't start on a block boundary.  Transfer the
  473.      * first few extra fragments to get things going on a block boundary.
  474.      */
  475.     register int extraFrags;
  476.  
  477.     extraFrags = FS_FRAGMENTS_PER_BLOCK -
  478.             (fragNumber % FS_FRAGMENTS_PER_BLOCK);
  479.     if (extraFrags > numFrags) {
  480.         extraFrags = numFrags;
  481.     }
  482.     firstSector = Fs_BlocksToSectors(fragNumber, devicePtr->data);
  483.     io.offset = firstSector * DEV_BYTES_PER_SECTOR;
  484.     io.length = extraFrags * FS_FRAGMENT_SIZE;
  485.     io.buffer = buffer;
  486.     status = (*devFsOpTable[devType].read)(devicePtr, &io, &reply);
  487.     extraFrags = reply.length / FS_FRAGMENT_SIZE;
  488.     fragNumber += extraFrags;
  489.     buffer += reply.length;
  490.     numFrags -= extraFrags;
  491.     }
  492.     if (numFrags > 0) {
  493.     /*
  494.      * Transfer the left over fragments.
  495.      */
  496.     firstSector = Fs_BlocksToSectors(fragNumber, devicePtr->data);
  497.     io.offset = firstSector * DEV_BYTES_PER_SECTOR;
  498.     io.length = numFrags * FS_FRAGMENT_SIZE;
  499.     io.buffer = buffer;
  500.     status = (*devFsOpTable[devType].read)(devicePtr, &io, &reply);
  501.     }
  502.     return(status);
  503. }
  504.  
  505. @
  506.  
  507.  
  508. 1.11
  509. log
  510. @checking this in for rab -- jhh
  511. @
  512. text
  513. @d28 1
  514. a28 1
  515. static char rcsid[] = "$Header: /sprite/src/boot/sunprom/RCS/fsDisk.c,v 1.10 90/09/17 11:04:41 jhh Exp Locker: rab $ SPRITE (Berkeley)";
  516. d39 1
  517. d93 1
  518. a93 1
  519.     Fsdm_SummaryInfo *summaryInfoPtr;    /* Pointer to summary info. */
  520. d127 1
  521. a127 1
  522.     Fsdm_DomainHeader    *domainHeaderPtr = (Fsdm_DomainHeader *) buffer;
  523. d133 1
  524. a133 1
  525.     numHeaderSectors = FSDM_NUM_DOMAIN_SECTORS;
  526. d136 1
  527. a136 1
  528.         io.length = DEV_BYTES_PER_SECTOR * FSDM_NUM_DOMAIN_SECTORS;
  529. d142 1
  530. a142 1
  531.         if (domainHeaderPtr->magic == FSDM_DOMAIN_MAGIC) {
  532. d157 2
  533. a158 1
  534.     fsDomainPtr->headerPtr = (Fsdm_DomainHeader *) buffer;
  535. d162 1
  536. a162 1
  537.      * Fsdm_Geometry part of the domain header.  This is used by the
  538. d165 2
  539. a166 1
  540.     fsDevicePtr->data = (ClientData)&fsDomainPtr->headerPtr->geometry;
  541. d211 1
  542. a211 1
  543.     register Fsdm_Geometry *geoPtr;
  544. d217 1
  545. a217 1
  546.     geoPtr         = (Fsdm_Geometry *)data;
  547. d273 1
  548. a273 1
  549.     register Fsdm_Geometry *geoPtr;
  550. d279 1
  551. a279 1
  552.     geoPtr         = (Fsdm_Geometry *)data;
  553. @
  554.  
  555.  
  556. 1.10
  557. log
  558. @brought it up-to-date with standard kernel sources
  559. @
  560. text
  561. @d28 1
  562. a28 1
  563. static char rcsid[] = "$Header: /sprite/src/boot/sunprom/RCS/fsDisk.c,v 1.9 90/07/17 15:42:26 mendel Exp Locker: jhh $ SPRITE (Berkeley)";
  564. d97 1
  565. d103 1
  566. a103 1
  567.     status = (*devFsOpTable[devType].open)(&fsDevice);
  568. @
  569.  
  570.  
  571. 1.9
  572. log
  573. @*** empty log message ***
  574. @
  575. text
  576. @d28 1
  577. a28 1
  578. static char rcsid[] = "$Header: /sprite/src/kernel/fs/RCS/fsDisk.c,v 8.7 89/06/02 12:57:50 jhh Exp Locker: jhh $ SPRITE (Berkeley)";
  579. d95 2
  580. d113 4
  581. a116 2
  582.     status = (*devFsOpTable[devType].read)(&fsDevice,
  583.         0, DEV_BYTES_PER_SECTOR, buffer, &amountRead);
  584. d124 3
  585. a126 1
  586.     if (((Sun_DiskLabel *)buffer)->magic != SUN_DISK_MAGIC) {
  587. d131 23
  588. a153 19
  589.     }
  590.  
  591.     headerSector = SUN_DOMAIN_SECTOR;
  592.     numHeaderSectors = FSDM_NUM_DOMAIN_SECTORS;
  593.     /*
  594.      * Read the domain header and save it with the domain state.
  595.      */
  596.     buffer = (Address)malloc(DEV_BYTES_PER_SECTOR * numHeaderSectors);
  597.     status = (*devFsOpTable[devType].read)(&fsDevice,
  598.         headerSector * DEV_BYTES_PER_SECTOR,
  599.         numHeaderSectors * DEV_BYTES_PER_SECTOR,
  600.         buffer, &amountRead);
  601.     if (status != SUCCESS) {
  602.     return(status);
  603.     } else if (((Fsdm_DomainHeader *)buffer)->magic != FSDM_DOMAIN_MAGIC) {
  604. #ifndef NO_PRINTF
  605.     printf("Bad magic <%x>\n", ((Fsdm_DomainHeader *)buffer)->magic);
  606. #endif
  607.     return(FAILURE);
  608. a154 1
  609.  
  610. a170 70
  611.  
  612.  
  613. /*
  614.  *----------------------------------------------------------------------
  615.  *
  616.  * IsSunLabel --
  617.  *
  618.  *    Poke around in the input buffer and see if it looks like
  619.  *    a Sun format disk label.
  620.  *
  621.  * Results:
  622.  *    TRUE or FALSE
  623.  *
  624.  * Side effects:
  625.  *    None.
  626.  *
  627.  *----------------------------------------------------------------------
  628.  */
  629. #ifdef notdef
  630. static Boolean
  631. IsSunLabel(buffer)
  632.     Address buffer;    /* Buffer containing zero'th sector */
  633. {
  634.     register Sun_DiskLabel *sunLabelPtr;
  635.  
  636.     sunLabelPtr = (Sun_DiskLabel *)buffer;
  637.     if (sunLabelPtr->magic == SUN_DISK_MAGIC) {
  638.     /*
  639.      * Should check checkSum...
  640.      */
  641.     return(TRUE);
  642.     } else {
  643.     return(FALSE);
  644.     }
  645. }
  646. #endif
  647.  
  648. /*
  649.  *----------------------------------------------------------------------
  650.  *
  651.  * IsSpriteLabel --
  652.  *
  653.  *    Poke around in the input buffer and see if it looks like
  654.  *    a Sprite format disk header.
  655.  *
  656.  * Results:
  657.  *    TRUE or FALSE
  658.  *
  659.  * Side effects:
  660.  *    None.
  661.  *
  662.  *----------------------------------------------------------------------
  663.  */
  664. #ifdef notdef
  665. static Boolean
  666. IsSpriteLabel(buffer)
  667.     Address buffer;    /* Buffer containing zero'th sector */
  668. {
  669.     register FsDiskHeader *diskHeaderPtr;
  670.     register int index;
  671.     register int checkSum;
  672.  
  673.     diskHeaderPtr = (FsDiskHeader *)buffer;
  674.     if (diskHeaderPtr->magic == FSDM_DISK_MAGIC) {
  675.         return(TRUE);
  676.     }
  677.     }
  678.     return(FALSE);
  679. }
  680. #endif
  681. d383 2
  682. d400 5
  683. a404 4
  684.     status = (*devFsOpTable[devType].read)(devicePtr,
  685.         firstSector * DEV_BYTES_PER_SECTOR,
  686.         extraFrags * FS_FRAGMENT_SIZE, buffer, &transferCount);
  687.     extraFrags = transferCount / FS_FRAGMENT_SIZE;
  688. d406 1
  689. a406 1
  690.     buffer += transferCount;
  691. d414 4
  692. a417 3
  693.     status = (*devFsOpTable[devType].read)(devicePtr,
  694.         firstSector * DEV_BYTES_PER_SECTOR,
  695.         numFrags * FS_FRAGMENT_SIZE, buffer, &transferCount);
  696. @
  697.  
  698.  
  699. 1.8
  700. log
  701. @New include files and constants due to source reorganization
  702. @
  703. text
  704. @d4 11
  705. a14 1
  706.  *    Routines related to managing local disks.
  707. d16 1
  708. a16 1
  709.  * Copyright 1986 Regents of the University of California
  710. d18 7
  711. d27 2
  712. a28 2
  713. #ifndef lint
  714. static char rcsid[] = "$Header: fsDisk.c,v 1.7 87/05/27 14:34:45 brent Exp $ SPRITE (Berkeley)";
  715. d34 1
  716. a34 3
  717. #include "fs.h"
  718. #include "fsDisk.h"
  719. #include "fsOpTable.h"
  720. d37 2
  721. a38 7
  722. #include "devInt.h"
  723. #include "sync.h"
  724. #include "mem.h"
  725. #include "byte.h"
  726.  
  727. #include "boot.h"
  728.  
  729. d40 2
  730. a41 1
  731.  * Forward declarations.
  732. d43 1
  733. a43 1
  734. void FsGetFileDesc();
  735. d46 1
  736. a46 2
  737.  * fsDevice is copied into all FsHandles.  It is used by the drivers to
  738.  * get to the partition and geometry information for the disk.
  739. d48 4
  740. a51 1
  741. Fs_Device fsDevice;
  742. d54 1
  743. a54 1
  744.  * fsDomainPtr and fsRootHandlePtr are used by Fs_Open.
  745. d56 4
  746. a59 5
  747. static FsDomain fsDomain;
  748. FsDomain *fsDomainPtr = &fsDomain;
  749. static FsHandle fsRootHandle;
  750. FsHandle *fsRootHandlePtr = &fsRootHandle;
  751. static char fsLabelBuffer[DEV_BYTES_PER_SECTOR];
  752. d66 12
  753. a77 7
  754.  *    Set things up so we can call FsBlockIO to read the disk.
  755.  *    This makes sure the disk is up and reads the domain header.
  756.  *    The domain information is saved in a global area.
  757.  *
  758.  * Results:
  759.  *    SUCCESS if the disk was readable and had a good volume header.
  760.  *
  761. d79 1
  762. a79 1
  763.  *    Sets up the FsDomainInfo for the domain.
  764. d84 2
  765. a85 4
  766. Fs_AttachDisk(ctlrNum, unitNum, partNum)
  767.     int ctlrNum;    /* Controller number from boot command */
  768.     int unitNum;    /* Unit number from boot command */
  769.     int partNum;    /* Partition number from boot command */
  770. d87 23
  771. a109 7
  772.     register ReturnStatus status;    /* Return code */
  773.     register int headerSector;        /* Starting sector of volume header */
  774.     register int numHeaderSectors;    /* Number of sectors in volume header */
  775.     register FsDomainHeader *headerPtr;    /* Domain information */
  776.     int sectorsRead;            /* Returned from read call */
  777.     /*
  778.      * Set up the global filesystem device, its type number is zero.
  779. d111 5
  780. a115 7
  781.     fsDevice.unit = unitNum;
  782. #ifdef SCSI_DISK_BOOT
  783.     fsDevice.type = FS_DEV_SCSI_DISK;
  784. #endif
  785. #ifdef XYLOGICS_BOOT
  786.     fsDevice.type = FS_DEV_XYLOGICS;
  787. #endif
  788. d117 4
  789. a120 9
  790.      * Read the zero'th sector from the first partition to get the layout
  791.      * of the disk.  A read failure will fall into the No Disk Label error
  792.      * message.
  793.      */
  794.     sectorsRead = 1;
  795.     status = (*fsRawDeviceOpsTable[fsDevice.type].readWrite)(FS_READ,
  796.          fsDevice.unit / DEV_NUM_DISK_PARTS,    /* first partiton */
  797.          fsLabelBuffer, 0, §orsRead);
  798.     if (((Sun_DiskLabel *)fsLabelBuffer)->magic == SUN_DISK_MAGIC) {
  799. d122 1
  800. a122 1
  801.      * For Sun formatted disks we put the volume header well past
  802. a124 10
  803.     headerSector = SUN_DOMAIN_SECTOR;
  804.     sectorsRead = FS_NUM_DOMAIN_SECTORS;
  805. #ifdef notdef
  806.     } else if (Fs_IsSpriteLabel(buffer)) {
  807.     headerSector = ((FsDiskHeader *)fsLabelBuffer)->domainSector;
  808.     sectorsRead = ((FsDiskHeader *)fsLabelBuffer)->numDomainSectors;
  809. #endif notdef
  810.     } else {
  811.     Sys_Printf("No label <%x>\n", status);
  812.     return(FAILURE);
  813. d126 3
  814. d130 1
  815. a130 2
  816.      * Read and save the domain header.  Every
  817.      * partition should have a domain header.
  818. d132 5
  819. a136 5
  820.     headerPtr = (FsDomainHeader *)Mem_Alloc(DEV_BYTES_PER_SECTOR *
  821.                         sectorsRead);
  822.     status = (*fsRawDeviceOpsTable[fsDevice.type].readWrite)(FS_READ,
  823.          fsDevice.unit, (Address)headerPtr, headerSector,
  824.          §orsRead);
  825. d139 5
  826. d146 6
  827. a151 8
  828.     fsDomainPtr->headerPtr = headerPtr;
  829.     if (headerPtr->magic != FS_DOMAIN_MAGIC) {
  830.     Sys_Printf("Bad magic <%x>\n", headerPtr->magic);
  831.     return(FAILURE);
  832.     }
  833.     /*
  834.      * Set up the device to reference the geometry information so we
  835.      * can do block IO.
  836. d153 2
  837. a154 3
  838.     fsDevice.data = (ClientData)&fsDomainPtr->headerPtr->geometry;
  839.     headerPtr->device = fsDevice;
  840.     
  841. d159 1
  842. a159 1
  843.     FsInitFileHandle(fsDomainPtr, FS_ROOT_FILE_NUMBER, fsRootHandlePtr);
  844. d162 70
  845. d235 9
  846. d262 1
  847. a262 1
  848. #ifdef SCSI_DISK_BOOT
  849. d264 3
  850. a266 3
  851. Fs_BlocksToSectors(fragNumber, geoPtr)
  852.     register int fragNumber;
  853.     register FsGeometry *geoPtr;
  854. d268 1
  855. d274 1
  856. d277 7
  857. a283 3
  858.     blockNumber        -= cylinder * geoPtr->blocksPerCylinder;
  859.     rotationalSet    = blockNumber / geoPtr->blocksPerRotSet;
  860.     blockNumber        -= rotationalSet * geoPtr->blocksPerRotSet;
  861. d285 14
  862. a298 5
  863.     sectorNumber = geoPtr->sectorsPerTrack * geoPtr->numHeads * cylinder +
  864.           geoPtr->sectorsPerTrack * geoPtr->tracksPerRotSet *
  865.           rotationalSet +
  866.           geoPtr->blockOffset[blockNumber];
  867.     sectorNumber += (fragNumber % FS_FRAGMENTS_PER_BLOCK) * SECTORS_PER_FRAG;
  868. d302 1
  869. a302 1
  870. #endif SCSI_DISK_BOOT
  871. d328 1
  872. a328 1
  873.     register Dev_DiskAddr *diskAddrPtr;
  874. d330 1
  875. a330 1
  876.     register FsGeometry *geoPtr;
  877. d336 1
  878. a336 1
  879.     geoPtr         = (FsGeometry *)data;
  880. d355 4
  881. d360 2
  882. a361 1
  883.                 rotationalSet + geoPtr->blockOffset[blockNumber] +
  884. d363 1
  885. d368 1
  886. a368 1
  887. #endif XYLOGICS_BOOT
  888. d393 5
  889. a397 4
  890.     register int sector;    /* Sector number, counting from zero  */
  891.     register int numSectors;    /* Number of sectors per track */
  892.     register int numHeads;    /* Number of heads on the disk */
  893.     register Dev_DiskAddr *diskAddrPtr;
  894. d407 2
  895. a408 1
  896. #endif XYLOGICS_BOOT
  897. d413 4
  898. a416 1
  899.  * Fs_IsSunLabel --
  900. d418 2
  901. a419 2
  902.  *    Poke around in the input buffer and see if it looks like
  903.  *    a Sun format disk label.
  904. d422 1
  905. a422 1
  906.  *    TRUE or FALSE
  907. d425 1
  908. a425 1
  909.  *    None.
  910. d429 23
  911. a451 6
  912. #ifdef notdef
  913. Boolean
  914. Fs_IsSunLabel(buffer)
  915.     Address buffer;    /* Buffer containing zero'th sector */
  916. {
  917.     register Sun_DiskLabel *sunLabelPtr;
  918. d453 15
  919. a467 2
  920.     sunLabelPtr = (Sun_DiskLabel *)buffer;
  921.     if (sunLabelPtr->magic == SUN_DISK_MAGIC) {
  922. d469 1
  923. a469 1
  924.      * Should check checkSum...
  925. d471 4
  926. a474 4
  927.     return(TRUE);
  928.     } else {
  929.     Sys_Printf("Sun magic <%x>\n", sunLabelPtr->magic);
  930.     return(FALSE);
  931. d476 1
  932. a477 24
  933. #endif
  934.  
  935. /*
  936.  *----------------------------------------------------------------------
  937.  *
  938.  * Fs_IsSpriteLabel --
  939.  *
  940.  *    Poke around in the input buffer and see if it looks like
  941.  *    a Sprite format disk header.
  942.  *
  943.  * Results:
  944.  *    TRUE or FALSE
  945.  *
  946.  * Side effects:
  947.  *    None.
  948.  *
  949.  *----------------------------------------------------------------------
  950.  */
  951. #ifdef notdef
  952. Boolean
  953. Fs_IsSpriteLabel(buffer)
  954.     Address buffer;    /* Buffer containing zero'th sector */
  955. {
  956.     register FsDiskHeader *diskHeaderPtr;
  957. a478 11
  958.     diskHeaderPtr = (FsDiskHeader *)buffer;
  959.     if (diskHeaderPtr->magic == FS_DISK_MAGIC) {
  960.     return(TRUE);
  961.     } else {
  962. #ifndef NO_PRINTF
  963.     Sys_Printf("Sprite magic <%x>\n", diskHeaderPtr->magic);
  964. #endif
  965.     return(FALSE);
  966.     }
  967. }
  968. #endif
  969. @
  970.  
  971.  
  972. 1.7
  973. log
  974. @Wasn't calling the correct device type read routine.
  975. @
  976. text
  977. @d11 1
  978. a11 1
  979. static char rcsid[] = "$Header: fsDisk.c,v 1.6 87/05/19 12:14:44 brent Exp $ SPRITE (Berkeley)";
  980. a17 1
  981. #include "fsInt.h"
  982. a18 1
  983. #include "fsLocalDomain.h"
  984. d20 1
  985. a20 2
  986. #include "fsPrefix.h"
  987. #include "sunDiskLabel.h"
  988. @
  989.  
  990.  
  991. 1.6
  992. log
  993. @Added mapping routines for drivers that need head/sector/cylinder
  994. addresses.
  995. @
  996. text
  997. @d11 1
  998. a11 1
  999. static char rcsid[] = "$Header: fsDisk.c,v 1.5 87/05/11 11:18:18 brent Exp $ SPRITE (Berkeley)";
  1000. d84 6
  1001. d96 1
  1002. a96 1
  1003.     status = (*fsRawDeviceOpsTable[0].readWrite)(FS_READ,
  1004. d112 1
  1005. a112 1
  1006.     Sys_Printf("No header <%x>\n", status);
  1007. d121 1
  1008. a121 1
  1009.     status = (*fsRawDeviceOpsTable[0].readWrite)(FS_READ,
  1010. @
  1011.  
  1012.  
  1013. 1.5
  1014. log
  1015. @Final trimmed down version
  1016. @
  1017. text
  1018. @d11 1
  1019. a11 1
  1020. static char rcsid[] = "$Header: fsDisk.c,v 1.4 87/05/08 17:45:18 brent Exp $ SPRITE (Berkeley)";
  1021. d30 2
  1022. d99 1
  1023. a99 1
  1024.     numHeaderSectors = FS_NUM_DOMAIN_SECTORS;
  1025. d103 1
  1026. a103 1
  1027.     numHeaderSectors = ((FsDiskHeader *)fsLabelBuffer)->numDomainSectors;
  1028. d106 1
  1029. a106 1
  1030.     Sys_Printf("No disk header <%x>\n", status);
  1031. d114 1
  1032. a114 1
  1033.                         numHeaderSectors);
  1034. d124 1
  1035. a124 1
  1036.     Sys_Printf("Bad disk magic <%x>\n", headerPtr->magic);
  1037. d162 1
  1038. d187 99
  1039. @
  1040.  
  1041.  
  1042. 1.4
  1043. log
  1044. @Updated to reflect changes in fs header files
  1045. @
  1046. text
  1047. @d11 1
  1048. a11 1
  1049. static char rcsid[] = "$Header: fsDisk.c,v 1.3 86/07/24 11:35:31 brent Exp $ SPRITE (Berkeley)";
  1050. a35 5
  1051.  * Global variables used because there is only one domain during a boot.
  1052.  */
  1053. Address fsLabelBuffer;
  1054.  
  1055. /*
  1056. d44 5
  1057. a48 2
  1058. FsDomain *fsDomainPtr;
  1059. FsHandle *fsRootHandlePtr;
  1060. a73 1
  1061.     register  Address buffer;        /* Read buffer */
  1062. a86 1
  1063.     buffer = (Address)Mem_Alloc(DEV_BYTES_PER_SECTOR);
  1064. d90 2
  1065. a91 2
  1066.          buffer, 0, §orsRead);
  1067.     if (Fs_IsSunLabel(buffer)) {
  1068. d98 1
  1069. d100 3
  1070. a102 2
  1071.     headerSector = ((FsDiskHeader *)buffer)->domainSector;
  1072.     numHeaderSectors = ((FsDiskHeader *)buffer)->numDomainSectors;
  1073. a106 1
  1074.     fsLabelBuffer = buffer;
  1075. a119 1
  1076.     fsDomainPtr = (FsDomain *)Mem_Alloc(sizeof(FsDomain));
  1077. a135 1
  1078.     fsRootHandlePtr = (FsHandle *)Mem_Alloc(sizeof(FsHandle));
  1079. d201 1
  1080. d219 1
  1081. d237 1
  1082. d254 1
  1083. @
  1084.  
  1085.  
  1086. 1.3
  1087. log
  1088. @more trimming
  1089. @
  1090. text
  1091. @d11 1
  1092. a11 1
  1093. static char rcsid[] = "$Header: fsDisk.c,v 1.2 86/07/21 09:36:00 brent Exp $ SPRITE (Berkeley)";
  1094. d90 1
  1095. a90 1
  1096.     buffer = (Address)Mem_Alloc(BYTES_PER_SECTOR);
  1097. d114 1
  1098. a114 1
  1099.     headerPtr = (FsDomainHeader *)Mem_Alloc(BYTES_PER_SECTOR *
  1100. d164 1
  1101. a164 1
  1102. #define SECTORS_PER_FRAG    (FS_FRAGMENT_SIZE / BYTES_PER_SECTOR)
  1103. d168 1
  1104. a168 1
  1105.     register Fs_Geometry *geoPtr;
  1106. @
  1107.  
  1108.  
  1109. 1.2
  1110. log
  1111. @Scrunched the code down.  Solidified Fs_AttachDisk
  1112. @
  1113. text
  1114. @d11 1
  1115. a11 1
  1116. static char rcsid[] = "$Header: fsDisk.c,v 1.1 86/07/18 09:32:40 brent Exp $ SPRITE (Berkeley)";
  1117. d78 1
  1118. a78 1
  1119.     int numHeaderSectors;        /* Number of sectors in volume header */
  1120. d118 1
  1121. a118 1
  1122.          &numHeaderSectors);
  1123. d126 1
  1124. a126 1
  1125.     Sys_Printf("FsDiskAttach: Bad magic # <%x>\n", headerPtr->magic);
  1126. d250 1
  1127. d252 1
  1128. @
  1129.  
  1130.  
  1131. 1.1
  1132. log
  1133. @Initial revision
  1134. @
  1135. text
  1136. @d11 1
  1137. a11 1
  1138. static char rcsid[] = "$Header: fsDisk.c,v 1.10 86/07/09 14:08:53 brent Exp $ SPRITE (Berkeley)";
  1139. d25 1
  1140. d33 1
  1141. a33 2
  1142. static Boolean IsSunLabel();
  1143. static Boolean IsSpriteLabel();
  1144. d35 4
  1145. a38 1
  1146. static Fs_Device fsDevice;
  1147. d40 5
  1148. a44 1
  1149. FsDomain *fsDomainPtr;    /* Top level info for the boot domain */
  1150. d46 5
  1151. a50 1
  1152. FsHandle *fsDiskHandlePtr;
  1153. d57 3
  1154. a59 7
  1155.  *    Make a file handle for the raw disk we are booting from.
  1156.  *    This makes sure the disk is up, reads the volume header,
  1157.  *    and calls the initialization routine for the block I/O module
  1158.  *    of the disk's driver.  By the time this is called the device
  1159.  *    initialization routines have already been called from Dev_Config
  1160.  *    so the device driver knows how the disk is partitioned into
  1161.  *    volumes.
  1162. d70 1
  1163. a70 1
  1164. Fs_AttachDisk(ctlrNum, unitNum, partNum, handlePtrPtr)
  1165. a73 1
  1166.     FsHandle **handlePtrPtr;    /* Return, handle for raw disk */
  1167. d75 6
  1168. a80 8
  1169.     ReturnStatus status;    /* Error code */
  1170.     Address buffer;        /* Read buffer */
  1171.     int headerSector;        /* Starting sector of volume header */
  1172.     int numHeaderSectors;    /* Number of sectors in volume header */
  1173.     int sectorsRead;        /* Returned from read call */
  1174.     FsHandle    *handlePtr;    /* Reference to file handle for root */
  1175.     FsFileID    fileID;        /* ID for root directory of domain */
  1176.  
  1177. a84 1
  1178.     buffer = (Address)Mem_Alloc(BYTES_PER_SECTOR);
  1179. d86 3
  1180. a88 7
  1181.      * This dives right down to the device specific I/O routines in order
  1182.      * to read the special info kept at the beginning of the volume.
  1183.      * Once the volume header has been read the regular block I/O interface
  1184.      * to the device can be used.
  1185.      * Read the zero'th sector of the partition.  It has a copy of the
  1186.      * disk header, and that describes how the rest of the zero'th
  1187.      * cylinder is layed out.
  1188. d90 1
  1189. d93 3
  1190. a95 8
  1191.          fsDevice.unit, buffer, 0, §orsRead);
  1192.     if (status != SUCCESS) {
  1193.     return(status);
  1194.     }
  1195.     /*
  1196.      * Check for different disk formats.
  1197.      */
  1198.     if (IsSunLabel(buffer)) {
  1199. d102 3
  1200. a104 5
  1201.     } else if (IsSpriteLabel(buffer)) {
  1202.     register FsDiskHeader *diskHeaderPtr;
  1203.     diskHeaderPtr = (FsDiskHeader *)buffer;
  1204.     headerSector = diskHeaderPtr->domainSector;
  1205.     numHeaderSectors = diskHeaderPtr->numDomainSectors;
  1206. d106 1
  1207. a106 1
  1208.     Sys_Printf("No disk header\n");
  1209. d109 1
  1210. d111 2
  1211. a112 1
  1212.      * Read the volume header and save it with the domain.
  1213. d114 2
  1214. a115 1
  1215.     buffer = (Address)Mem_Alloc(BYTES_PER_SECTOR * numHeaderSectors);
  1216. d117 2
  1217. a118 1
  1218.          fsDevice.unit, buffer, headerSector, &numHeaderSectors);
  1219. d124 3
  1220. a126 4
  1221.     fsDomainPtr->headerPtr = (FsDomainHeader *)buffer;
  1222.     if (fsDomainPtr->headerPtr->magic != FS_DOMAIN_MAGIC) {
  1223.     Sys_Printf("FsDiskAttach: Bad magic # on volume header <%x>\n",
  1224.                   fsDomainPtr->headerPtr->magic);
  1225. d130 2
  1226. a131 5
  1227.      * Call the Block I/O initialization routine which sets up the
  1228.      * ClientData part of *devicePtr to reference the Fs_Geometry
  1229.      * part of the domain header.  Then overwrite the device
  1230.      * specification at was on the disk because the device unit depends on
  1231.      * the system configuration.
  1232. d133 9
  1233. a141 11
  1234.     (*fsBlockOpsTable[0].init)(&fsDevice, &fsDomainPtr->headerPtr->geometry);
  1235.     fsDomainPtr->headerPtr->device = fsDevice;
  1236.  
  1237.     fsDiskHandlePtr = (FsHandle *)Mem_Alloc(sizeof(FsHandle));
  1238.     fsDiskHandlePtr->fileID.serverID = -1;
  1239.     fsDiskHandlePtr->fileID.domain = 0;
  1240.     fsDiskHandlePtr->fileID.fileNumber = 0;
  1241.     fsDiskHandlePtr->fileID.version = -1;
  1242.     fsDiskHandlePtr->domainToken = (ClientData)fsDomainPtr;
  1243.  
  1244.     *handlePtrPtr = fsDiskHandlePtr;
  1245. d148 10
  1246. a157 1
  1247.  * IsSunLabel --
  1248. d159 36
  1249. d206 2
  1250. a207 2
  1251. static Boolean
  1252. IsSunLabel(buffer)
  1253. d219 1
  1254. d227 1
  1255. a227 1
  1256.  * IsSpriteLabel --
  1257. d240 2
  1258. a241 2
  1259. static Boolean
  1260. IsSpriteLabel(buffer)
  1261. a244 2
  1262.     register int index;
  1263.     register int checkSum;
  1264. d250 1
  1265. a252 45
  1266. }
  1267.  
  1268. /*
  1269.  *----------------------------------------------------------------------
  1270.  *
  1271.  * Fs_BlocksToSectors --
  1272.  *
  1273.  *    Convert from block indexes (actually, fragment indexes) to
  1274.  *    sectors using the geometry information on the disk.  This
  1275.  *    is a utility for block device drivers.
  1276.  *
  1277.  * Results:
  1278.  *    The sector number that corresponds to the fragment index.
  1279.  *    The caller has to make sure that its I/O doesn't cross a
  1280.  *    filesystem block boundary.
  1281.  *
  1282.  * Side effects:
  1283.  *    None.
  1284.  *
  1285.  *----------------------------------------------------------------------
  1286.  */
  1287. #define SECTORS_PER_FRAG    (FS_FRAGMENT_SIZE / BYTES_PER_SECTOR)
  1288. int
  1289. Fs_BlocksToSectors(fragNumber, geoPtr)
  1290.     int fragNumber;
  1291.     register Fs_Geometry *geoPtr;
  1292. {
  1293.     register int sectorNumber;    /* The sector corresponding to the fragment */
  1294.     register int cylinder;    /* The cylinder number of the fragment */
  1295.     register int rotationalSet;    /* The rotational set with cylinder of frag */
  1296.     register int blockNumber;    /* The block number within rotational set */
  1297.  
  1298.     blockNumber        = fragNumber / FS_FRAGMENTS_PER_BLOCK;
  1299.     cylinder        = blockNumber / geoPtr->blocksPerCylinder;
  1300.     blockNumber        -= cylinder * geoPtr->blocksPerCylinder;
  1301.     rotationalSet    = blockNumber / geoPtr->blocksPerRotSet;
  1302.     blockNumber        -= rotationalSet * geoPtr->blocksPerRotSet;
  1303.  
  1304.     sectorNumber = geoPtr->sectorsPerTrack * geoPtr->numHeads * cylinder +
  1305.           geoPtr->sectorsPerTrack * geoPtr->tracksPerRotSet *
  1306.           rotationalSet +
  1307.           geoPtr->blockOffset[blockNumber];
  1308.     sectorNumber += (fragNumber % FS_FRAGMENTS_PER_BLOCK) * SECTORS_PER_FRAG;
  1309.  
  1310.     return(sectorNumber);
  1311. @
  1312.